package com.xmall.controller.admin;

import com.xmall.bean.vo.BaseRespVo;
import com.xmall.bean.table.Ad;
import com.xmall.service.AdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("admin/ad")
public class AdController {

    @Autowired
    private AdService adService;

    @RequestMapping("list")
    public BaseRespVo list(@RequestParam Map<String, String> params){
        Map<String, Object> result = adService.queryList(params);
        return BaseRespVo.ok(result);
    }


    @RequestMapping("create")
    public BaseRespVo create(@RequestBody Ad adCreate){
        //todo
        adCreate= adService.createAd(adCreate);
        return BaseRespVo.ok(adCreate);
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody Ad adUpdate){
        //todo
        adUpdate = adService.updateAd(adUpdate);
        return BaseRespVo.ok(adUpdate);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Ad adDelete){
        //todo
        adService.deleteAd(adDelete);
        return BaseRespVo.ok();
    }
}
